<template>
  <PageTabelLayout>
    <template #pageHeader>
      <div class="search-form" v-if="pageData.headerShow">
        <a-form size="mini" :model="pageData" layout="inline">
          <a-form-item label="仓库类型">
            <a-select popup-container="html" 
              class="bacClass"
              :style="{ width: '10rem' }"
              @change="whChange"
              placeholder=""
              v-model="searchData.whTypeName"
              allow-clear
            >
              <a-option v-for="item in whTypeList" :value="item.typeName">
                {{ item.typeName }}
              </a-option>
            </a-select>
          </a-form-item>
          <CorporateSectorCascader
            ref="cascaderRef"
            :configCascader="configCascader"
            @changeCascader="changeCascader"
          />
          <!-- <a-form-item label="选择公司">
                        <a-select popup-container="html"  class="bacClass" :style="{ width: '10rem' }" @change="companyChange" placeholder=""
                            v-model="searchData.firm" allow-clear>
                            <a-option v-for="item in companyList" :value="item.id">
                                {{ item.typeName ? item.typeName + '-' + item.firmName : item.firmName }}
                            </a-option>
                        </a-select>
                    </a-form-item> -->

          <a-form-item label="仓库">
            <a-select popup-container="html" 
              class="bacClass"
              :style="{ width: '10rem' }"
              placeholder=""
              v-model="searchData.wh"
              @change="isWhilist"
              @click="ckisPd"
              allow-clear
            >
              <a-option v-for="item in whList" :value="item.id">
                {{ item.warehouseName }}
              </a-option>
            </a-select>
          </a-form-item>
          <a-form-item label="入库状态">
            <a-select popup-container="html" 
              class="bacClass"
              :style="{ width: '10rem' }"
              placeholder=""
              v-model="searchData.stats"
              allow-clear
            >
              <a-option :value="0">待入库</a-option>
              <a-option :value="1">已入库</a-option>
            </a-select>
          </a-form-item>
        </a-form>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="pageData.headerShow"
            @click="pageData.headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down
            v-else
            @click="pageData.headerShow = true"
            :strokeWidth="2"
            :size="18"
          />
        </a-divider>
      </div>
      <div class="my-tool-bar">
        <Toolbar
          :items="titelisLbs"
          @cjCg="cjCgs"
          @add="addHandler"
          @select="selectHandler"
          @cjYl="cjYls"
          @reders="redersz"
        >
        </Toolbar>
      </div>
    </template>
    <template #pageTabel>
      <a-tabs   :lazy-load="true" :justify="true" @change="cxKeyss" :default-active-key="1">
        <a-tab-pane title="已处理" :key="1">
          <!-- <a-table :style="{
                                    height: '100%'
                                }" size="mini" :scrollbar="true" sticky-header @page-change="pagination.change" stripe
                                    :bordered="true" :columns="baseCol"
                                    :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }"
                                    v-model:selected-keys="selectedRowKeys" :loading="pageData.pageLoading" :data="table.dataList"
                                    :pagination="{ size: 'mini', current: pagination.page, pageSize: pagination.pageSize, total: pagination.total }"
                                    rowKey="orderNo">
                                    <template #action="{ record }">
                                        <a-space>
                                            <a-button v-if="record.auditState === 0" type="primary" size="mini" status="warning"
                                                @click="xingXg(record)">
                                                <template #icon>
                                                    <icon-edit />
                                                </template>
                                                修 改
                                            </a-button>
                                            <a-button v-else type="primary" size="mini" status="warning" disabled>
                                                <template #icon>
                                                    <icon-edit />
                                                </template>
                                                修 改
                                            </a-button>
                                            <a-button type="primary" size="mini" @click="dyingMx(record)">
                                                <template #icon>
                                                    <icon-archive />
                                                </template>
                                                打 印
                                            </a-button>
                                            <a-button type="outline" status="success" size="mini" @click="isXiang(record)">
                                                <template #icon>
                                                    <icon-find-replace />
                                                </template>
                                                详 情
                                            </a-button>
                                            <a-button type="outline" v-if="(record.auditState == 0 || record.auditState == 1)"
                                                size="mini" @click="deletWh(record)">
                                                <template #icon>
                                                    <icon-delete />
                                                </template>
                                                删 除
                                            </a-button>
                                            <a-button type="outline" v-else size="mini" disabled>
                                                <template #icon>
                                                    <icon-delete />
                                                </template>
                                                删除
                                            </a-button>
                                        </a-space>
                                    </template>
                                    <template #auditState="{ record }">
                                        <a-button v-if="(record.auditState == 0)" type="primary" status="warning" size="mini"
                                            disabled>待&nbsp;审&nbsp;核&nbsp;
                                        </a-button>
                                        <a-button v-if="(record.auditState == 2)" status="success" size="mini" disabled>审核通过
                                        </a-button>
                                        <a-button v-if="(record.auditState == 1)" type="primary" size="mini" status="danger"
                                            disabled>审核驳回
                                        </a-button>
                                    </template>
                                </a-table> -->
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33"
            rowSelection="multiple"
            @grid-ready="gridReady"
            style="height: 100%"
            :defaultColDef="defaultColDef"
            class="ag-theme-alpine"
            :rowData="table.dataList"
            :columnDefs="tc"
            :localeText="localeText1"
          ></AgGridVuesCopys>
        </a-tab-pane>
        <a-tab-pane title="待处理" :key="2">
          <a-table
            :style="{
              height: '500px',
              marginTop: '10px',
            }"
            :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }"
            rowKey="tempId"
            v-model:selected-keys="selectedRowKeys1"
            stripe
            :bordered="{ cell: true }"
            :scrollbar="true"
            sticky-header
            :pagination="false"
            :columns="tableColumns2"
            :data="cgListXqs"
          >
          </a-table>
        </a-tab-pane>
      </a-tabs>
    </template>
    <paginationCopys
      :total="total"
      show-total
      show-jumper
      show-page-size
      @change="PageSize"
      @page-size-change="change1"
      style="justify-content: center"
      :page-size="size"
      :current="page"
    />
    <a-drawer
      ok-text="保存"
      cancel-text="关闭"
      :style="{ zIndex: 999 }"
      :mask-closable="false"
      :height="600"
      :visible="pageData.showAdd"
      unmountOnClose
      @ok="sicksOk"
      placement="bottom"
      @cancel="sicksNo"
    >
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div>
        <a-space>
          <a-button
            size="mini"
            type="primary"
            v-if="pageData.sideTitle != '新增(采购单)'"
            @click="tjWlzl"
            >添加</a-button
          >
        </a-space>
        <div style="height: 10px"></div>
        <a-table
          :style="{
            height: '100%',
            marginTop: '10px',
          }"
          stripe
          :bordered="true"
          :scrollbar="true"
          :pagination="false"
          sticky-header
          :columns="tableColumns"
          :data="tableSjList"
        >
          <template v-for="(item, index) in tableColumns" #[item.slotName]="{ record }">
            <div v-if="item.ls != '' && item.dropState == 1">
              <a-select popup-container="html" 
                class="bacClass"
                v-model="record[item.slotName]"
                allow-clear
                @click="dongTypeSelce(record, item)"
                @change="changsType(item, record)"
              >
                <a-option v-for="items in isDtas" :value="items[item.slotName]">
                  {{ items[item.slotName] }}
                </a-option>
              </a-select>
            </div>
            <div
              v-else-if="
                item.ls != '' &&
                item.dropState == 0 &&
                item.slotName != 'pieceNumber' &&
                item.slotName != 'bulkNumber' &&
                item.slotName != 'bulkWeight' &&
                item.slotName != 'pieceWeight'
              "
            >
              <a-input
                disabled
                v-if="item.slotName != 'totalNum'"
                v-model="record[item.slotName]"
              ></a-input>
              <a-input-number
                disabled
                v-if="item.slotName == 'totalNum'"
                :precision="2"
                v-model="record[item.slotName]"
              ></a-input-number>
            </div>
            <div
              v-else-if="
                item.ls == '' || (item.ls == undefined && index != tableColumns.length - 1)
              "
            >
              <a-input
                v-if="
                  item.slotName == 'firm' ||
                  item.slotName == 'warehouseName' ||
                  item.slotName == 'warehouseTypeName'
                "
                disabled
                v-model="record[item.slotName]"
              ></a-input>
              <a-input
                class="bacClass"
                v-else-if="
                  item.slotName != 'firm' &&
                  item.slotName != 'warehouseName' &&
                  item.slotName != 'warehouseTypeName' &&
                  item.slotName != 'pieceNumber' &&
                  item.slotName != 'bulkNumber' &&
                  item.slotName != 'bulkWeight' &&
                  item.slotName != 'pieceWeight' &&
                  item.valueType == 0
                "
                v-model="record[item.slotName]"
              ></a-input>
              <a-input-number
                class="bacClass"
                v-else-if="
                  item.slotName != 'firm' &&
                  item.slotName != 'warehouseName' &&
                  item.slotName != 'warehouseTypeName' &&
                  item.slotName != 'pieceNumber' &&
                  item.slotName != 'bulkNumber' &&
                  item.slotName != 'bulkWeight' &&
                  item.slotName != 'pieceWeight' &&
                  item.valueType == 1
                "
                v-model="record[item.slotName]"
                :min="1"
              ></a-input-number>
              <a-input-number
                class="bacClass"
                v-else-if="
                  item.slotName != 'firm' &&
                  item.slotName != 'warehouseName' &&
                  item.slotName != 'warehouseTypeName' &&
                  item.slotName != 'pieceNumber' &&
                  item.slotName != 'bulkNumber' &&
                  item.slotName != 'bulkWeight' &&
                  item.slotName != 'pieceWeight' &&
                  item.valueType == 2
                "
                v-model="record[item.slotName]"
                :precision="2"
              ></a-input-number>
              <a-input-number
                class="bacClass"
                v-else-if="
                  item.slotName != 'firm' &&
                  item.slotName != 'warehouseName' &&
                  item.slotName != 'warehouseTypeName' &&
                  item.slotName == 'pieceNumber'
                "
                v-model="record['pieceNumber']"
                @change="pieceNumbers($event, record)"
              ></a-input-number>
              <a-input-number
                class="bacClass"
                v-else-if="
                  item.slotName != 'firm' &&
                  item.slotName != 'warehouseName' &&
                  item.slotName != 'warehouseTypeName' &&
                  item.slotName == 'bulkNumber'
                "
                v-model="record['bulkNumber']"
                @change="bulkNumbers($event, record)"
              ></a-input-number>
              <a-input-number
                class="bacClass"
                v-else-if="
                  item.slotName != 'firm' &&
                  item.slotName != 'warehouseName' &&
                  item.slotName != 'warehouseTypeName' &&
                  item.slotName == 'bulkWeight'
                "
                v-model="record['bulkWeight']"
                :precision="2"
                @change="bulkWeights($event, record)"
              ></a-input-number>
            </div>
            <div v-if="index != tableColumns.length - 1">
              <a-input-number
                class="bacClass"
                v-if="item.slotName == 'pieceWeight'"
                v-model="record['pieceWeight']"
                :precision="2"
                @change="pieceWeights($event, record)"
              ></a-input-number>
            </div>
            <a-button
              v-if="index == tableColumns.length - 1"
              type="outline"
              size="mini"
              @click="deletWhsWl(record)"
            >
              <template #icon>
                <icon-delete />
              </template>
              删除
            </a-button>
          </template>
        </a-table>
      </div>
    </a-drawer>
    <a-modal v-model:visible="visible" title="详情" :width="1200" :footer="false" :draggable="true">
      <a-table
        :style="{
          height: '500px',
          marginTop: '10px',
        }"
        stripe
        :bordered="true"
        :scrollbar="true"
        sticky-header
        :pagination="false"
        :columns="tableColumns1"
        :data="whListMingxs"
      >
      </a-table>
    </a-modal>
    <a-modal v-model:visible="visiblecg" ok-text="打印" @ok="print" @cancel="cancels" :width="1200">
      <template #title> 入库单打印 </template>
      <div id="receipt">
        <div id="dys">
          <QrcodeVue :value="qrData.code"></QrcodeVue>
          <div>
            <p>打印人:&nbsp;&nbsp;{{ qrData.dyData }}</p>
            <p>打印时间:&nbsp;&nbsp;{{ qrData.dyTime }}</p>
            <p>单号:&nbsp;&nbsp;{{ qrData.dyCode }}</p>
          </div>
        </div>
        <table class="isTable">
          <tr>
            <th v-for="item in btList">{{ item.chineseName }}</th>
            <!-- <th v-for=" item in btList">{{ item[Object.keys(item)[0]] }}</th> -->
          </tr>
          <tr v-for="items in jsList">
            <td v-for="item in btList">{{ items[item.englishName] }}</td>
          </tr>
        </table>
      </div>
    </a-modal>
    <a-modal
      :width="1200"
      v-model:visible="visibleCg"
      :on-before-ok="handleOk"
      @cancel="handleCancel"
      :mask-closable="false"
    >
      <template #title> 选择采购单入库 </template>
      <div class="cgisDatas">
        <div>
          <span>选择采购单:</span>
          <a-select popup-container="html" 
            class="bacClass"
            v-model="isCgds"
            :style="{ width: '150px' }"
            @search="cxCgisLists"
            @click="cxCgisList"
            allow-search
            allow-clear
          >
            <a-option v-for="item in cgListArray">{{ item.purchaseCode }}</a-option>
          </a-select>
        </div>
        <div>
          <span>物料编号:</span
          ><a-input class="bacClass" v-model="isWlCodeds" :style="{ width: '150px' }" allow-clear />
        </div>
        <div>
          <span>物料名称:</span
          ><a-input class="bacClass" v-model="isWlNameds" :style="{ width: '150px' }" allow-clear />
        </div>
        <a-button type="primary" size="mini" @click="cxCgsList">查询</a-button>
      </div>
      <a-table
        :style="{
          height: '500px',
          marginTop: '10px',
        }"
        :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }"
        rowKey="tempId"
        v-model:selected-keys="selectedRowKeys1"
        stripe
        :bordered="true"
        :scrollbar="true"
        sticky-header
        :pagination="false"
        :columns="tableColumns2"
        :data="cgListXqs"
      >
      </a-table>
    </a-modal>

    <a-modal
      :width="1200"
      v-model:visible="visibleYl"
      :on-before-ok="handleOks"
      @cancel="handleCancels"
      :mask-closable="false"
    >
      <template #title> 选择原料入库 </template>
      <div class="cgisDatas">
        <div>
          <span>原料编号:</span
          ><a-input class="bacClass" v-model="isLyCodeds" :style="{ width: '150px' }" allow-clear />
        </div>
        <div>
          <span>原料名称:</span
          ><a-input class="bacClass" v-model="isLyNameds" :style="{ width: '150px' }" allow-clear />
        </div>
        <a-button type="primary" size="mini" @click="cxCgsLists">查询</a-button>
      </div>
      <a-table
        :style="{
          height: '500px',
          marginTop: '10px',
        }"
        :row-selection="{ showCheckedAll: true, width: 50, onlyCurrent: true }"
        rowKey="typeLesIds"
        v-model:selected-keys="selectedRowKeys2"
        stripe
        :bordered="true"
        :scrollbar="true"
        sticky-header
        :pagination="false"
        :columns="tableColumns3"
        :data="wlListXqs"
      >
      </a-table>
    </a-modal>
  </PageTabelLayout>
</template>

<script lang="ts">
import { post, get } from '@/api/http'
import { useTable, useRowKey, useTableColumn, usePagination, useRowSelection } from '@/hooks/table'

import { ref, reactive, h, watch } from 'vue'
import Toolbar from '@/components/Toolbar.vue'

import PageTabelLayout from '@/components/pageTabelLayout.vue'
import TreeUtils from '@/utils/TreeUtils'

import WHService, { Warhouse, CompanyList, WhTypeField } from '@/service/wh'
import { Message, Modal } from '@arco-design/web-vue'
import { tableColumns } from '@/components/processrowfactory/useTableList'
import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
import {
  IconDoubleUp,
  IconDoubleDown,
  IconEdit,
  IconFindReplace,
  IconDelete,
} from '@arco-design/web-vue/es/icon'
import pagination from '@arco-design/web-vue/es/pagination'
import QrcodeVue from 'qrcode.vue'
import printJS from 'print-js'

import { localeText } from '@/api/aggridZw'

export default {
  name: 'ReceiptList',
  setup() {
    const visiblecg = ref(false)
    const whService = new WHService()
    const whList = ref<any[]>([])
    const whTypeList = whService.whTypeList

    const whTypeFieldList = whService.whTypeFieldList
    const treeUtils = new TreeUtils()
    const companyList: any = whService.companyList
    const searchData = reactive<{
      whTypeName: string
      firm: string
      firmId: string | number
      wh: string
      stats: any
    }>({
      firm: '',
      whTypeName: '',
      wh: '',
      stats: '',
      firmId: '',
    })
    let cascaderRef = ref('')
    let configCascader = ref<{}>({
      corporateWidth: '180px', //公司宽度
      sectorWidth: '180px', //部门宽度
      corporateRquired: false, //公司是否必填
      sectorRquired: false, //部门是否必填
      size: 'mini', //选择框大小'mini' | 'small' | 'medium' | 'large'
      corporateName: '选择公司', //公司label
      sectorName: '选择部门', //部门label
      cascaderShow: 'sector', //配置部门不显示
    })
    interface obj {
      sectorId: ''
      corporateId: ''
      corporateLabel: ''
      sectorLabel: ''
    }
    const changeCascader = (data: obj) => {
      const { corporateId, sectorId, sectorLabel, corporateLabel } = data
      searchData.firmId = corporateId
      searchData.firm = corporateLabel
    }
    const baseCol: any[] = [
      {
        dataIndex: 'orderNo',
        key: 'orderNo',
        title: '单据编号',
        width: 180,
      },
      {
        dataIndex: 'firm',
        key: 'firm',
        title: '公司',
        width: 150,
      },
      {
        dataIndex: 'warehouseTypeName',
        key: 'warehouseTypeName',
        title: '仓库类型',
        width: 150,
      },
      {
        dataIndex: 'warehouseName',
        key: 'warehouseName',
        title: '仓库',
        width: 150,
      },
      {
        dataIndex: 'auditName',
        key: 'auditName',
        title: '审核人',
        width: 100,
      },
      {
        title: '审核时间',
        dataIndex: 'auditTime',
        key: 'auditTime',
        width: 100,
      },
      {
        title: '创建人',
        dataIndex: 'createName',
        key: 'createName',
        width: 150,
      },
      {
        title: '创建时间',
        dataIndex: 'createTime',
        key: 'createTime',
        width: 150,
      },
      {
        title: '修改人',
        dataIndex: 'updateName',
        key: 'updateName',
        width: 150,
      },
      {
        title: '修改时间',
        dataIndex: 'updateTime',
        key: 'updateTime',
        width: 150,
      },
      {
        title: '单据状态',
        dataIndex: 'infoState',
        key: 'infoState',
        slotName: 'infoState',
        fixed: 'right',
        width: 150,
      },
      {
        title: '审核状态',
        dataIndex: 'auditState',
        slotName: 'auditState',
        width: 100,
        key: 'auditState',
        fixed: 'right',
      },
      {
        title: '操作',
        fixed: 'right',
        slotName: 'action',
        width: 320,
      },
    ]

    const total = ref(10)
    const page = ref(1)
    const size = ref(10)
    function PageSize(val: any) {
      page.value = val
      doRefresh()
    }
    function change1(val: any) {
      size.value = val
      doRefresh()
    }

    function doRefresh() {
      let warehouseNames
      whList.value.forEach((items: any) => {
        if (items.id == searchData.wh) {
          warehouseNames = items.warehouseName
        }
      })
      pageData.pageLoading = true
      post({
        url: 'wms/WarehousetypeFieldvalue/getInvoicesByPage',
        data: {
          page: page.value,
          size: size.value,
          warehouseTypeName: searchData.whTypeName,
          firmId: searchData.firm,
          infoType: 1,
          infoState: searchData.stats,
          warehouseName: warehouseNames,
        },
      })
        .then(({ data, code }: any) => {
          if (code === 200) {
            table.handleSuccess(data.list)
            gridOption.value.setRowData(data.list)
            pagination.setTotalSize(data.total)
            total.value = data.total
          }
        })
        .catch(console.log)
        .finally(() => {
          pageData.pageLoading = false
        })
    }

    const { selectedRowKeys, onSelectionChange } = useRowSelection()
    const pagination = usePagination(doRefresh)
    const table = useTable()
    const rowKey = useRowKey('id')
    let tableColumns: any = ref([])
    let tableColumns1: any = ref([])
    let tableListDatas = reactive({
      typeLesIds: 0,
    })
    watch(
      () => whService.whTypeFieldList.value,
      () => {
        //  baseCol.splice(3,0, ...(whService.whTypeFieldList.value.map((f:any)=>{
        //     return {
        //         dataIndex:f.extendField,
        //         key:f.extendField,
        //         title:f.fieldName,
        //         width:150
        //     }
        // })))
        tableColumns.value = whService.whTypeFieldList.value.map((f: any) => {
          return {
            dataIndex: f.englishName,
            key: f.englishName,
            title: f.chineseName,
            slotName: f.englishName,
            width: 150,
            ls: f.ls,
            dropState: f.dropState,
            conditions: f.conditions,
            valueType: f.valueType,
            mustState: f.mustState,
          }
        })
        tableColumns1.value = whService.whTypeFieldList.value.map((f: any) => {
          if (f.englishName == 'rawMaterialName') {
            return {
              dataIndex: f.englishName,
              key: f.englishName,
              title: f.chineseName,
              slotName: f.englishName,
              width: 450,
            }
          } else if (f.englishName == 'rawMaterialCode') {
            return {
              dataIndex: f.englishName,
              key: f.englishName,
              title: f.chineseName,
              slotName: f.englishName,
              width: 200,
            }
          } else if (f.englishName == 'sourceOrderNo') {
            return {
              dataIndex: f.englishName,
              key: f.englishName,
              title: f.chineseName,
              slotName: f.englishName,
              width: 200,
            }
          } else if (f.englishName == 'planMaterialCode') {
            return {
              dataIndex: f.englishName,
              key: f.englishName,
              title: f.chineseName,
              slotName: f.englishName,
              width: 200,
            }
          } else {
            return {
              dataIndex: f.englishName,
              key: f.englishName,
              title: f.chineseName,
              slotName: f.englishName,
              width: 150,
            }
          }
        })
        tableColumns1.value.unshift(
          {
            dataIndex: 'orderNo',
            key: 'orderNo',
            title: '单据编号',
            width: 180,
          }
          // , {
          //     dataIndex: 'firm',
          //     key: 'firm',
          //     title: '公司',
          //     width: 150
          // }, {
          //     dataIndex: 'warehouseTypeName',
          //     key: 'warehouseTypeName',
          //     title: '仓库类型',
          //     width: 150
          // },
          //     {
          //         dataIndex: 'warehouseName',
          //         key: 'warehouseName',
          //         title: '仓库',
          //         width: 150
          //     }
        )
        tableColumns.value.push({
          title: '操作',
          fixed: 'right',
          slotName: 'action',
          width: 150,
        })
        whService.whTypeFieldList.value.forEach((item: any) => {
          tableListDatas[item.englishName] = ''
        })
      }
    )

    const pageData = reactive<{
      showAdd: boolean
      sideTitle: string
      pageLoading: boolean
      headerShow: boolean
    }>({
      showAdd: false,
      sideTitle: '新增入库单',
      pageLoading: false,
      headerShow: true,
    })

    const addHandler = () => {
      if (searchData.whTypeName == '' || searchData.wh == '' || searchData.firm == '') {
        Message.error('请先选择主页仓库类型或选择公司或仓库')
      } else {
        pageData.sideTitle = '新增入库单'
        pageData.showAdd = true
      }
    }
    const selectHandler = () => {
      if (searchData.whTypeName == '' || searchData.wh == '' || searchData.firm == '') {
        Message.error('请先选择主页仓库类型或选择公司或仓库')
      } else {
        if (cxKeys.value == 1) {
          page.value = 1
          doRefresh()
        } else if (cxKeys.value == 2) {
          cxCgsList()
        }
      }
    }
    const whChange = (val: any) => {
      if (val == '五金仓') {
        // titelisLbs.value = ['新增(采购单)', '查询', '新增']

        if (cxKeys.value == 1) {
          titelisLbs.value = ['查询', '新增']
        } else if (cxKeys.value == 2) {
          titelisLbs.value = ['查询', '入库']
        }
      } else if (val == '原纱仓') {
        titelisLbs.value = ['新增(原纱仓)', '查询', '新增']
      } else {
        if (cxKeys.value == 1) {
          titelisLbs.value = ['查询', '新增']
        } else if (cxKeys.value == 2) {
          titelisLbs.value = ['查询', '入库']
        }
      }

      whList.value = []
      searchData.wh = ''
      searchData.firm = ''
    }
    watch(
      () => whService.whList.value,
      (o, n) => {
        whList.value = whService.whList.value
      }
    )
    // 公司下拉框 改变
    const companyChange = (val: any) => {
      whList.value = []
      searchData.wh = ''
      whService.getWarhouseList(val, searchData.whTypeName)
    }

    let visible = ref(false)
    let whListMingxs = ref<any[]>([])
    const isXiang = async (val: any) => {
      const res: any = await whService.getWarhouseMinxList(
        val.orderNo,
        val.warehouseTypeName,
        val.warehouseName,
        val.firmId
      )
      if (res.code == 200) {
        whListMingxs.value = res.data
        visible.value = true
      }
    }
    let tableSjList: any = ref([])
    const tjWlzl = () => {
      tableListDatas.typeLesIds++
      tableSjList.value.push(JSON.parse(JSON.stringify(tableListDatas)))
      tableSjList.value.forEach((item: any) => {
        item['warehouseTypeName'] = searchData.whTypeName
        item['warehouseId'] = searchData.wh
        whList.value.forEach((items: any) => {
          if (items.id == searchData.wh) {
            item['warehouseName'] = items.warehouseName
          }
        })
        item['firmId'] = searchData.firm
        companyList.value.forEach((items: any) => {
          if (items.id == searchData.firm) {
            item['firm'] = items.typeName ? items.typeName + '-' + items.firmName : items.firmName
          }
        })
        item['infoType'] = 1
      })
    }
    const sicksOk = async () => {
      if (tableSjList.value.length == 0) {
        Message.error('请先新增入库数据')
        return false
      }

      for (let i = 0; i < tableSjList.value.length; i++) {
        var o = tableSjList.value[i]
        for (let j = 0; j < tableColumns.value.length; j++) {
          var item = tableColumns.value[j]
          if (item.mustState == 1) {
            if (item.valueType == 0) {
              if (
                o[item.slotName] == '' ||
                o[item.slotName] == undefined ||
                o[item.slotName] == null
              ) {
                Message.error(item.title + '必填不能为空')
                return false
              }
            } else {
              // 数字大于0
              if (
                o[item.slotName] == '' ||
                o[item.slotName] == undefined ||
                o[item.slotName] == null ||
                o[item.slotName] <= 0
              ) {
                Message.error(item.title + '必填不能为空')
                return false
              }
            }
          }
        }
      }
      if (pageData.sideTitle == '新增(原纱仓)') {
        for (var i = 0; i < tableSjList.value.length; i++) {
          for (var j = i + 1; j < tableSjList.value.length; j++) {
            if (tableSjList.value[i].rawMaterialCode === tableSjList.value[j].rawMaterialCode) {
              Message.error('原料编号重复')
              return false
            }
          }
        }
      }

      tableListDatas.typeLesIds = 0
      if (
        pageData.sideTitle == '新增入库单' ||
        pageData.sideTitle == '新增(采购单)' ||
        pageData.sideTitle == '新增(原纱仓)'
      ) {
        tableSjList.value.forEach((item: any) => {
          for (let items in item) {
            if (item[items] == '') {
              item[items] = null
            }
          }
        })

        const res: any = await whService.addWarhouseMinxList(tableSjList.value)
        if (res.code == 200) {
          tableSjList.value = []
          doRefresh()
          cxCgsList()
          Message.success('添加成功')
          pageData.showAdd = false
        } else {
          Message.error(res.message)
        }
      } else if (pageData.sideTitle == '修改入库单') {
        tableSjList.value.forEach((item: any) => {
          item['warehouseTypeName'] = searchData.whTypeName
          item['warehouseId'] = searchData.wh
          whList.value.forEach((items: any) => {
            if (items.id == searchData.wh) {
              item['warehouseName'] = items.warehouseName
            }
          })
          item['firmId'] = searchData.firm
          companyList.value.forEach((items: any) => {
            if (items.id == searchData.firm) {
              item['firm'] = items.typeName ? items.typeName + '-' + items.firmName : items.firmName
            }
          })
          item['infoType'] = 1
          item['orderNo'] = orderNos
          item['createName'] = tableSjList.value[0].createName
          item['createTime'] = tableSjList.value[0].createTime
        })
        let updataWhdataList = {
          warehouseTypeName: searchData.whTypeName,
          warehouseName: whList.value.map((item: any) => {
            if ((item.id = searchData.wh)) {
              return item.warehouseName
            }
          })[0],
          firmId: searchData.firm,
          updateInfo: tableSjList.value,
        }
        const res: any = await whService.updataWarhouseMinxList(updataWhdataList)
        if (res.code == 200) {
          orderNos = ''
          tableSjList.value = []
          doRefresh()
          Message.success('修改成功')
          pageData.showAdd = false
        } else {
          Message.error(res.message)
        }
      }
    }
    const sicksNo = () => {
      tableListDatas.typeLesIds = 0
      tableSjList.value = []
      pageData.showAdd = false
    }
    let orderNos: any
    const xingXg = async (val: any) => {
      orderNos = val.orderNo
      const res = await whService.getWarhouseMinxList(
        val.orderNo,
        val.warehouseTypeName,
        val.warehouseName,
        val.firmId
      )
      if (res.code == 200) {
        tableSjList.value = res.data
        pageData.sideTitle = '修改入库单'
        pageData.showAdd = true
      }
    }

    const deletWh = (val: any) => {
      let objDelet = {
        warehouseTypeName: val.warehouseTypeName,
        warehouseName: val.warehouseName,
        firmId: val.firmId,
        delOrderNoInfo: [val.orderNo],
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk: async () => {
          const res: any = await whService.deletWarhouseMinxList(objDelet)
          if (res.code == 200) {
            Message.success('删除成功')
            doRefresh()
          } else {
            Message.error(res.message)
          }
        },
      })
    }
    const deletWhsWl = (val: any) => {
      let objDelet = {
        warehouseTypeName: val.warehouseTypeName,
        warehouseName: val.warehouseName,
        firmId: val.firmId,
        delInfo: [val.id],
      }
      Modal.confirm({
        title: '系统提示',
        content: '确认删除选中的数据?',
        onOk: async () => {
          if (val.id == undefined) {
            if (val.tempId != undefined || val.tempId != null) {
              tableSjList.value.forEach((item: any, index: any) => {
                if (val.tempId == item.tempId) {
                  tableSjList.value.splice(index, 1)
                }
              })
              if (tableSjList.value.length == 0) {
                pageData.showAdd = false
              }
            } else {
              tableSjList.value.forEach((item: any, index: any) => {
                if (val.typeLesIds == item.typeLesIds) {
                  tableSjList.value.splice(index, 1)
                }
              })
              if (tableSjList.value.length == 0) {
                pageData.showAdd = false
              }
            }
          } else {
            const res: any = await whService.deletWhmxWarhouseMinxList(objDelet)
            if (res.code == 200) {
              Message.success('删除成功')
              const resz: any = await whService.getWarhouseMinxList(
                val.orderNo,
                val.warehouseTypeName,
                val.warehouseName,
                val.firmId
              )
              if (resz.code == 200) {
                if (resz.data.length == 0) {
                  whListMingxs.value = resz.data
                  tableSjList.value = resz.data
                  doRefresh()
                  pageData.showAdd = false
                } else {
                  whListMingxs.value = resz.data
                  tableSjList.value = resz.data
                }
              }
            } else {
              Message.error(res.message)
            }
          }
        },
      })
    }
    const zsList: any = ref([])
    const btList: any = ref<any[]>([])
    const jsList: any = ref([])
    const qrData = reactive({
      dyTime: '',
      dyData: '',
      dyCode: '',
      code: '',
    })
    const dyingMx = async (val: any) => {
      let isDataObj = {
        warehouseTypeName: val.warehouseTypeName,
        warehouseName: val.warehouseName,
        firmId: val.firmId,
        orderNo: val.orderNo,
      }
      const res: any = await whService.DyWhmxWarhouse([isDataObj])
      if (res.code == 200) {
        zsList.value = res.data
        qrData.dyTime = res.data[0].printTime
        qrData.dyData = res.data[0].printName
        qrData.dyCode = res.data[0].orderNo
        qrData.code = JSON.stringify({
          warehouseCode: encodeURI(res.data[0].warehouseCode),
          warehouseTypeCode: encodeURI(res.data[0].warehouseTypeCode),
          orderNo: encodeURI(res.data[0].orderNo),
          infoType: Number(1),
        })
        btList.value = res.data[0].tableHead
        // for (let item in res.data[0].tableHead) {
        //     btList.value.push({
        //         [item]: res.data[0].tableHead[item]
        //     })
        // }
        jsList.value = res.data[0].info
        visiblecg.value = true
      } else {
        Message.error(res.message)
      }
    }
    const print = () => {
      printJS({
        printable: 'receipt',
        type: 'html',
        targetStyles: ['*'],
      })
      zsList.value = []
      btList.value = []
      jsList.value = []
      for (let item in qrData) {
        qrData[item] = ''
      }
    }
    const cancels = () => {
      zsList.value = []
      btList.value = []
      jsList.value = []
      for (let item in qrData) {
        qrData[item] = ''
      }
    }
    let isDtas = ref([])
    const dongTypeSelce = async (record: any, val: any) => {
      var paramList: any = []
      var ob: any = {}
      if (val.conditions.length > 0) {
        let conditions = val.conditions
        for (let i = 0; i < conditions.length; i++) {
          if (conditions[i].extendField != null && conditions[i].extendField != '') {
            if (
              record[conditions[i].extendField] == null ||
              record[conditions[i].extendField] == ''
            ) {
              let column = tableColumns.value.filter(function (o: any) {
                return o.key == conditions[i].extendField
              })[0]
              if (column != null || column != '') {
                Message.error('请先输入' + column.title)
              }
              return
            } else {
              ob[conditions[i].extendField] = record[conditions[i].extendField]
            }
          }
        }
      }
      ob['ls'] = val.ls
      paramList.push(ob)
      const res = await whService.liusuiCkSmWhmxWarhouse(paramList)
      if (res.code == 200) {
        isDtas.value = res.data[val.ls]
      }
    }
    const changsType = (ob: any, record: any) => {
      if (record[ob.slotName] == '') {
        for (let key in isDtas.value[0]) {
          record[key] = ''
        }
      } else {
        isDtas.value.forEach((item: any) => {
          if (item[ob.slotName] == record[ob.slotName]) {
            for (let key in item) {
              record[key] = item[key]
            }
          }
        })
      }
    }
    const ckisPd = () => {
      if (searchData.whTypeName == '' || searchData.firm == '') {
        Message.error('请先选择仓库类型和所属工厂')
        return
      }
    }
    const isWhilist = (whName: any) => {
      // let isWhId;
      // whList.value.forEach((item: any) => {
      //     if (whName == item.warehouseName) {
      //         isWhId = item.id
      //     }
      // })
      whService.loadWHTypeFieldList({ warehouseId: whName, showType: 1 })
    }

    const visibleCg = ref(false)

    const cjCgs = () => {
      if (searchData.whTypeName == '' || searchData.wh == '' || searchData.firm == '') {
        Message.error('请先选择主页仓库类型或选择公司或仓库')
      } else {
        pageData.sideTitle = '新增(采购单)'
        visibleCg.value = true
      }
    }
    // @ok="handleOk" @cancel="handleCancel"
    const isCgds: any = ref('')
    const handleOk = () => {
      // console.log(666)
      // await new Promise(resolve => setTimeout(resolve, 1000));
      // return false;

      // if(isCgds.value != ''){
      //     const res:any =await whService.cgCxMxSmWhmxWarhouse({purchaseCode:isCgds.value})
      //     if(res.code == 200){
      //         tableSjList.value = res.data
      //         tableSjList.value.forEach((item: any) => {
      //         item['warehouseTypeName'] = searchData.whTypeName
      //         item['warehouseName'] = searchData.wh
      //         item['firmId'] = searchData.firm
      //         companyList.value.forEach((items:any)=>{
      //             if(items.id == searchData.firm){
      //                 item['firm'] =  items.typeName ? items.typeName + '-' + items.firmName : items.firmName
      //             }
      //         })
      //         item['infoType'] = 1
      //     })
      //         isCgds.value = ''
      //         pageData.showAdd = true
      //     }else{
      //         Message.error(res.message)
      //         return false
      //     }
      // }else{
      //     Message.error('请选择采购单')
      //     return false
      // }
      if (selectedRowKeys1.value.length == 0) {
        Message.error('请勾选数据')
        return false
      }
      let islistArray: any = []
      selectedRowKeys1.value.forEach((v: any) => {
        cgListXqs.value.forEach((o: any) => {
          if (v == o.tempId) {
            islistArray.push(o)
          }
        })
      })
      // purchaseOrderNo
      if (islistArray.length != 0) {
        tableSjList.value = islistArray
        tableSjList.value.forEach((item: any) => {
          item['warehouseTypeName'] = searchData.whTypeName
          item['warehouseId'] = searchData.wh
          whList.value.forEach((items: any) => {
            if (items.id == searchData.wh) {
              item['warehouseName'] = items.warehouseName
            }
          })
          item['firmId'] = searchData.firm
          companyList.value.forEach((items: any) => {
            if (items.id == searchData.firm) {
              item['firm'] = items.typeName ? items.typeName + '-' + items.firmName : items.firmName
            }
          })
          item['infoType'] = 1
          item['oldTotalNum'] = item.totalNum
          item['totalNum'] = item.notInStockNum
        })
        for (var i = 0; i < tableSjList.value.length; i++) {
          for (var j = i + 1; j < tableSjList.value.length; j++) {
            if (tableSjList.value[i].purchaseOrderNo != tableSjList.value[j].purchaseOrderNo) {
              Message.error('请选择相同采购单入库')
              return false
            }
          }
        }
        // cgListXqs.value = []
        // isCgds.value = ''
        // selectedRowKeys1.value = []
        pageData.showAdd = true
        return true
      }
    }

    const handleCancel = () => {
      visibleCg.value = false
    }

    const cgListArray: any = ref([])

    const cxCgisList = async () => {
      const res: any = await whService.cgCxSmWhmxWarhouse({
        firmId: searchData.firm,
        purchaseCode: '',
      })
      if (res.code == 200) {
        cgListArray.value = res.data
      } else {
        Message.error(res.message)
      }
    }
    const cxCgisLists = async (value: any) => {
      const res: any = await whService.cgCxSmWhmxWarhouse({
        firmId: searchData.firm,
        purchaseCode: value,
      })
      if (res.code == 200) {
        cgListArray.value = res.data
      } else {
        Message.error(res.message)
      }
    }
    const selectedRowKeys1: any = ref([])

    const tableColumns2: any = [
      {
        dataIndex: 'purchaseOrderNo',
        key: 'purchaseOrderNo',
        title: '采购单号',
        width: 150,
      },
      {
        dataIndex: 'supplierName',
        key: 'supplierName',
        title: '供应商',
        width: 150,
      },
      {
        dataIndex: 'buyer',
        key: 'buyer',
        title: '采购员',
        width: 150,
      },
      {
        dataIndex: 'clientName',
        key: 'clientName',
        title: '客户名称',
        width: 150,
      },
      {
        dataIndex: 'materialName',
        key: 'materialName',
        title: '物料名称',
        width: 150,
      },
      {
        dataIndex: 'materialCode',
        key: 'materialCode',
        title: '物料编号',
        width: 150,
      },
      {
        dataIndex: 'specification',
        key: 'specification',
        title: '规格',
        width: 150,
      },
      {
        dataIndex: 'unit',
        key: 'unit',
        title: '单位',
        width: 150,
      },
      {
        dataIndex: 'totalNum',
        key: 'totalNum',
        title: '采购数量',
        width: 150,
      },
      {
        dataIndex: 'inStockNum',
        key: 'inStockNum',
        title: '已入库数量 ',
        width: 150,
      },
      {
        dataIndex: 'notInStockNum',
        key: 'notInStockNum',
        title: '未入库数量',
        width: 150,
      },
      {
        dataIndex: 'price',
        key: 'price',
        title: '单价',
        width: 150,
      },
      {
        dataIndex: 'noTaxMoney',
        key: 'noTaxMoney',
        title: '价格',
        width: 150,
      },
      {
        dataIndex: 'taxMoney',
        key: 'taxMoney',
        title: '含税单价',
        width: 150,
      },
    ]
    const cgListXqs: any = ref()
    const cxCgsList = async () => {
      // isWlNameds,
      // isWlCodeds,
      const res: any = await whService.cgCxMxSmWhmxWarhouse({
        purchaseCode: isCgds.value,
        firmId: searchData.firm,
        materialCode: isWlCodeds.value,
        materialName: isWlNameds.value,
      })
      if (res.code == 200) {
        cgListXqs.value = res.data
      }
    }
    const isWlCodeds: any = ref()
    const isWlNameds: any = ref()
    // ['新增(采购单)', '查询', '新增']
    const titelisLbs: any = ref(['查询', '新增'])

    const gridOption = ref()
    const gridReady = (params: any) => {
      gridOption.value = params.api
    }
    const defaultColDef = {
      sortable: true,
      resizable: true,
      filter: true,
    }
    let tc: any[] = baseCol.map((o: any) => {
      let obj = {
        headerName: o.title,
        field: o.key,
        pinned: o['fixed'],
        width: 150,
      }
      if (o.slotName === 'action') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['width'] = 350
        obj['cellRenderer'] = {
          template: `
                    
          <a-space>
                                <a-button v-if="isDtas.auditState === 0" type="primary" size="mini" status="warning"
                                    @click="a1">
                                    <template #icon>
                                        <icon-edit />
                                    </template>
                                    修 改
                                </a-button>
                                <a-button v-else type="primary" size="mini" status="warning" disabled>
                                    <template #icon>
                                        <icon-edit />
                                    </template>
                                    修 改
                                </a-button>
                                <a-button type="primary" size="mini" @click="a2">
                                    <template #icon>
                                        <icon-archive />
                                    </template>
                                    打 印
                                </a-button>
                                <a-button type="outline" status="success" size="mini" @click="a3">
                                    <template #icon>
                                        <icon-find-replace />
                                    </template>
                                    详 情
                                </a-button>
                                <a-button type="outline" v-if="(isDtas.auditState == 0 || isDtas.auditState == 1)"
                                    size="mini" @click="a4">
                                    <template #icon>
                                        <icon-delete />
                                    </template>
                                    删 除
                                </a-button>
                                <a-button type="outline" v-else size="mini" disabled>
                                    <template #icon>
                                        <icon-delete />
                                    </template>
                                    删除
                                </a-button>
                            </a-space>
                    `,
          setup(props: any) {
            const isDtas = ref(props.params.data)
            const a1 = () => {
              xingXg(props.params.data)
            }
            const a2 = () => {
              dyingMx(props.params.data)
            }
            const a3 = () => {
              isXiang(props.params.data)
            }
            const a4 = () => {
              deletWh(props.params.data)
            }
            return {
              a1,
              a2,
              a3,
              a4,
              isDtas,
            }
          },
        }
      }
      if (o.slotName === 'auditState') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['width'] = 120
        obj['cellRenderer'] = {
          template: `<a-button v-if="(isDatas.auditState == 0)" type="primary" status="warning" size="mini"
                                disabled>待&nbsp;审&nbsp;核&nbsp;
                            </a-button>
                            <a-button v-if="(isDatas.auditState == 2)" status="success" size="mini" disabled>审核通过
                            </a-button>
                            <a-button v-if="(isDatas.auditState == 1)" type="primary" size="mini" status="danger"
                                disabled>审核驳回
                            </a-button>`,
          setup(props: any) {
            const isDatas = ref(props.params.data)
            return {
              isDatas,
            }
          },
        }
      }
      if (o.slotName === 'infoState') {
        obj['resizable'] = false
        obj['filter'] = false
        obj['sortable'] = false
        obj['lockPosition'] = 'right'
        obj['width'] = 100
        obj['cellRenderer'] = {
          template: `
                            <a-button v-if="(isDatas.infoState == 0)" status="success" size="mini" disabled>待入库
                            </a-button>
                            <a-button v-if="(isDatas.infoState == 1)" type="primary" size="mini" status="danger"
                                disabled>已入库
                            </a-button>`,
          setup(props: any) {
            const isDatas = ref(props.params.data)
            return {
              isDatas,
            }
          },
        }
      }
      return obj
    })

    let a = [
      {
        showRowGroup: 'hide_def',
        headerName: '',
        checkboxSelection: true,
        headerCheckboxSelection: true,
        pinned: 'left',
        width: 50,
        resizable: false,
        filter: false,
        sortable: false,
        minWidth: 50,
        maxWidth: 50,
        lockPosition: 'left',
      },
    ]
    tc = a.concat(tc)
    const visibleYl = ref(false)
    const cjYls = () => {
      if (searchData.whTypeName == '' || searchData.wh == '' || searchData.firm == '') {
        Message.error('请先选择主页仓库类型或选择公司或仓库')
      } else {
        pageData.sideTitle = '新增(原纱仓)'
        visibleYl.value = true
      }
    }

    const wlListXqs: any = ref([])

    const cxCgsLists = async () => {
      // isLyCodeds isLyNameds
      const res: any = await whService.wlCxMxSmWhmxWarhouse({
        rawmaterialCode: isLyCodeds.value,
        materialsName: isLyNameds.value,
      })
      if (res.code == 200) {
        wlListXqs.value = res.data
        wlListXqs.value.forEach((item: any) => {
          item['typeLesIds'] = tableListDatas.typeLesIds++
        })
      }
    }

    const tableColumns3: any = [
      {
        dataIndex: 'rawMaterialCode',
        key: 'rawMaterialCode',
        title: '原料编号',
        width: 150,
      },
      {
        dataIndex: 'rawMaterialName',
        key: 'rawMaterialName',
        title: '原料名称',
        width: 150,
      },
      {
        dataIndex: 'brandName',
        key: 'brandName',
        title: '纱牌',
        width: 150,
      },
      {
        dataIndex: 'pieceWeight',
        key: 'pieceWeight',
        title: '整件/件重',
        width: 150,
      },
      {
        dataIndex: 'unit',
        key: 'unit',
        title: '单位',
        width: 150,
      },
    ]

    const selectedRowKeys2 = ref([])
    const isLyCodeds: any = ref('')
    const isLyNameds: any = ref('')
    const handleCancels = () => {
      isLyCodeds.value = ''
      isLyNameds.value = ''
      wlListXqs.value = []
      selectedRowKeys2.value = []
      visibleCg.value = false
    }
    const handleOks = () => {
      if (selectedRowKeys2.value.length == 0) {
        Message.error('请勾选数据')
        return false
      }
      let islistArray: any = []
      selectedRowKeys2.value.forEach((v: any) => {
        wlListXqs.value.forEach((o: any) => {
          if (v == o.typeLesIds) {
            islistArray.push(o)
          }
        })
      })
      if (islistArray.length != 0) {
        tableSjList.value = islistArray
        tableSjList.value.forEach((item: any) => {
          item['warehouseTypeName'] = searchData.whTypeName
          item['warehouseId'] = searchData.wh
          whList.value.forEach((items: any) => {
            if (items.id == searchData.wh) {
              item['warehouseName'] = items.warehouseName
            }
          })
          item['firmId'] = searchData.firm
          companyList.value.forEach((items: any) => {
            if (items.id == searchData.firm) {
              item['firm'] = items.typeName ? items.typeName + '-' + items.firmName : items.firmName
            }
          })
          item['infoType'] = 1
          item['oldTotalNum'] = item.totalNum
          item['pieceNumber'] = 0
          item['bulkNumber'] = 0
          item['bulkWeight'] = 0
          item['totalNum'] =
            item['pieceNumber'] * item['pieceWeight'] + item['bulkNumber'] * item['bulkWeight']
        })

        isLyCodeds.value = ''
        isLyNameds.value = ''
        wlListXqs.value = []
        selectedRowKeys2.value = []
        visibleCg.value = false
        pageData.showAdd = true
        return true
      }
    }
    const pieceNumbers = ($event: any, record: any) => {
      if ($event == null || $event == undefined || $event == '') {
        record['pieceNumber'] = 0
        record['totalNum'] = 0 * record['pieceWeight'] + record['bulkNumber'] * record['bulkWeight']
      } else {
        record['totalNum'] =
          $event * record['pieceWeight'] + record['bulkNumber'] * record['bulkWeight']
      }
    }
    const bulkNumbers = ($event: any, record: any) => {
      if ($event == null || $event == undefined || $event == '') {
        record['bulkNumber'] = 0
        record['totalNum'] =
          0 * record['bulkWeight'] + record['pieceNumber'] * record['pieceWeight']
      } else {
        record['totalNum'] =
          $event * record['bulkWeight'] + record['pieceNumber'] * record['pieceWeight']
      }
    }
    const bulkWeights = ($event: any, record: any) => {
      if ($event == null || $event == undefined || $event == '') {
        record['bulkWeight'] = 0
        record['totalNum'] =
          0 * record['bulkNumber'] + record['pieceNumber'] * record['pieceWeight']
      } else {
        record['totalNum'] =
          $event * record['bulkNumber'] + record['pieceNumber'] * record['pieceWeight']
      }
    }
    const pieceWeights = ($event: any, record: any) => {
      if ($event == null || $event == undefined || $event == '') {
        record['pieceWeight'] = 0
        record['totalNum'] = 0 * record['pieceNumber'] + record['bulkNumber'] * record['bulkWeight']
      } else {
        record['totalNum'] =
          $event * record['pieceNumber'] + record['bulkNumber'] * record['bulkWeight']
      }
    }

    const localeText1: any = ref(localeText)
    const cxKeys: any = ref(1)
    const cxKeyss = (e: any) => {
      cxKeys.value = e
      if (e == 2) {
        titelisLbs.value = ['查询', '入库']
      } else if (e == 1) {
        titelisLbs.value = ['查询', '新增']
      }
    }
    const redersz = () => {
      handleOk()
    }
    watch(
      () => cxKeys.value,
      () => {
        if (cxKeys.value == 1) {
          titelisLbs.value = ['查询', '新增']
          doRefresh()
          // cxCgsList()
        } else if (cxKeys.value == 2) {
          titelisLbs.value = ['查询', '入库']
          // doRefresh()
          cxCgsList()
        }
      }
    )
    return {
      cascaderRef,
      configCascader,
      changeCascader,
      redersz,
      cxKeys,
      cxKeyss,
      localeText1,
      pieceWeights,
      bulkWeights,
      bulkNumbers,
      pieceNumbers,
      change1,
      PageSize,
      total,
      page,
      size,
      handleOks,
      handleCancels,
      isLyNameds,
      isLyCodeds,
      selectedRowKeys2,
      tableColumns3,
      wlListXqs,
      cxCgsLists,
      visibleYl,
      cjYls,
      tc,
      defaultColDef,
      gridReady,
      gridOption,
      titelisLbs,
      isWlNameds,
      isWlCodeds,
      cxCgsList,
      cgListXqs,
      tableColumns2,
      selectedRowKeys1,
      isCgds,
      cxCgisLists,
      cgListArray,
      cxCgisList,
      handleCancel,
      handleOk,
      visibleCg,
      cjCgs,
      isWhilist,
      ckisPd,
      changsType,
      isDtas,
      dongTypeSelce,
      qrData,
      cancels,
      zsList,
      btList,
      jsList,
      print,
      visiblecg,
      dyingMx,
      deletWhsWl,
      deletWh,
      xingXg,
      sicksNo,
      sicksOk,
      tableSjList,
      tableListDatas,
      tjWlzl,
      whListMingxs,
      isXiang,
      visible,
      companyChange,
      whChange,
      selectHandler,
      addHandler,
      companyList,
      whList,
      whTypeList,
      selectedRowKeys,
      whTypeFieldList,
      pagination,
      tableColumns,
      tableColumns1,
      table,
      rowKey,
      pageData,
      searchData,
      baseCol,
    }
  },
  components: { PageTabelLayout, QrcodeVue, CorporateSectorCascader },
}
</script>
<style scoped lang="less">
.isTable {
  margin-top: 100px;
  width: 90%;
  margin: 0 auto;
  border: 1.2px solid #ccc;
  text-align: center;
  border-collapse: collapse;

  td {
    border: 1.2px solid #ccc;
  }

  th {
    border: 1.2px solid #ccc;
  }
}

#receipt {
  width: 100%;

  #dys {
    width: 90%;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
  }
}

.cgisDatas {
  display: flex;
  justify-content: space-between;
}
</style>
